package com.bjpowernode.controller;

import com.bjpowernode.pojo.Admin;
import com.bjpowernode.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;

@Controller
@RequestMapping("/admin")
public class AdminAction {
    //切记在所有界面层都会有业务逻辑层对象
    @Autowired
    AdminService adminService;
    //实现登录判断并跳转
    @RequestMapping("/login")
    public String login(String name, String pwd, HttpServletRequest request){

        Admin admin =adminService.login(name,pwd);
        if (admin !=null){
            //成功
            request.setAttribute("admin",admin);
            return "main";
        }else {
            //失败
            request.setAttribute("errmsg","用户名或密码不正确");
            return "login";
        }


    }
}
